package com.design_pattern._02_structure._03_flyweight;

import java.util.HashMap;
import java.util.Map;

public class Flyweight {
    String name = this.getClass().getSimpleName();

    private static Map<String, Flyweight> data= new HashMap<String, Flyweight>();

    public static Flyweight get(String name){
        if (data.containsKey(name)){
            return data.get(name);
        }
        // 创建对应的对象，然后将对象存入缓存data中
        Flyweight generate = generate(name);
        data.put(generate.name, generate); // 生成对象的方法应该是单例，不然有并发问题发生
        return generate;
    }

    /**
     * 生成对应对象
     */
    private static Flyweight generate(String name){
        return null;
    }
}

class Tea extends Flyweight {
}

class RedTea extends Tea {
}

class GreenTea extends Tea {
}

class Food extends Flyweight{
}


class Cookie extends Food {
}


class Bread extends Food {
}

